package com.itheima.edu.info.manager.system.dao;

import com.itheima.edu.info.manager.system.domain.Teacher;

/**
 * 操作老师数据的类
 */
public class TeacherDao  implements ITeacherDao{

    //老师数据
    private static Teacher[] teachers= new Teacher[50];

    //增
    //分析形参   Teacher  teacher
    //分析 返回值 void
    public void xinZeng(Teacher  teacher){
        //找个空位放进去
        for (int i = 0; i < teachers.length; i++) {
            //teachers[i]
            if(teachers[i]==null){
                teachers[i]= teacher;
                break;
            }
        }
        //这里数组如果满了就放不下了
    }


    //删
    //分析 入参 String id
    //分析返回值 void
    public void shanChu(String id){
        //根据id 找索引
        int i = huoQuSuoYin(id);

        //把对应索引上的值改为null
        teachers[i]=null;
    }
    //改
    //入参  String id   Teacher  teacher
    //返回值  void
    public void xiuGai(String id,Teacher  teacher){
        //根据id 找索引
        int i = huoQuSuoYin(id);

        //把对应索引上的值改为传进来的对象
        teachers[i]=teacher;
    }

    //查询所有
    public Teacher[] chaXunSuoYou(){
        return teachers;
    }

    //根据id 查 索引
    //入参  String id
    //返回值 int index
    public int huoQuSuoYin(String id){
        for (int i = 0; i < teachers.length; i++) {
        //teachers[i]
            Teacher teacher = teachers[i];
            if(teacher!=null&&teacher.getId().equals(id)){
                return i;
            }
        }

        return -1;
    }
}
